#pragma once

static inline void arch_local_irq_disable(void)
{
    __asm__ volatile(
        "	cpsid i			@ arch_local_irq_disable"
        :
        :
        : "memory", "cc");
}

static inline void arch_local_irq_enable(void)
{
    __asm__ volatile(
        " cpsie i"
        :
        :
        : "memory", "cc");
}

#define arch_local_irq_save arch_local_irq_save
static inline unsigned long arch_local_irq_save(void)
{
    unsigned long flags;

    __asm__ volatile(
        "	mrs	%0, "
        "primask"
        "	@ arch_local_irq_save\n"
        "	cpsid	i"
        : "=r"(flags) : : "memory", "cc");

    return flags;
}

#define arch_local_irq_restore arch_local_irq_restore
static inline void arch_local_irq_restore(unsigned long flags)
{
    __asm__ volatile(
        "	msr	"
        "primask"
        ", %0	@ local_irq_restore"
        :
        : "r"(flags)
        : "memory", "cc");
}

static inline unsigned arch_irqs_disabled(void)
{
    unsigned long flags;
    unsigned ret;

    __asm__ volatile(
        "	mrs	%0, "
        "primask"
        "	@ arch_irqs_disabled\n"
        : "=r"(flags) : : "memory", "cc");

    ret = (flags & 1);

    return ret;
}
